package cn.itsource.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.itsource.constants.Constants;
import cn.itsource.constants.ErrorCode;
import cn.itsource.domain.BillDto;
import cn.itsource.exception.GlobalException;
import cn.itsource.mapper.OrderBillMapper;
import cn.itsource.openfeign.DriverSummaryOpenFeign;
import cn.itsource.openfeign.ValuationOpenFeign;
import cn.itsource.pojo.domain.DriverSettingRedisDto;
import cn.itsource.pojo.domain.Login;
import cn.itsource.pojo.domain.Order;
import cn.itsource.mapper.OrderMapper;
import cn.itsource.pojo.domain.OrderBill;
import cn.itsource.pojo.dto.*;
import cn.itsource.pojo.vo.CheckRunningOrderVo;
import cn.itsource.pojo.vo.FromLocation;
import cn.itsource.pojo.vo.KillOrderVo;
import cn.itsource.pojo.vo.ToLocation;
import cn.itsource.result.JSONResult;
import cn.itsource.service.IOrderService;
import cn.itsource.utils.CacheConstants;
import cn.itsource.utils.CodeGenerateUtils;
import cn.itsource.utils.IdUtil;
import cn.itsource.utils.RConst;
import com.alibaba.druid.sql.visitor.functions.If;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer;
import org.apache.rocketmq.client.consumer.PullResult;
import org.apache.rocketmq.client.consumer.PullStatus;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageQueue;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.*;
import org.springframework.data.redis.connection.RedisGeoCommands;
import org.springframework.data.redis.core.GeoOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 订单表 服务实现类
 * </p>
 *
 * @author tt
 * @since 2024-09-20
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {
    /**
     * 1.保存订单数据--(todo保存账单)
     * 2.根据起点的经纬度找redis里面 一定范围司机 -- 多个
     * 3.从多个司机找对应的redis的配置  过滤不符合 司机
     * 4.将对应的订单推送给 符合标准的司机（MQ推送）
     * 5.返回 成功或者失败
     * @param orderDto
     * @return
     */

    @Autowired
    private ValuationOpenFeign valuationOpenFeign;

    @Autowired
    private OrderBillMapper orderBillMapper;

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Autowired
    private DefaultMQPullConsumer pullConsumer;

    @Autowired
    private RedissonClient redissonClient;

    @Autowired
    private DriverSummaryOpenFeign driverSummaryOpenFeign;

    @Override
    public JSONResult save(OrderDto orderDto) {
        //1.保存订单数据
        //获取当前登陆人的登陆Id
        Long loginId = StpUtil.getLoginIdAsLong();
        //判断当前是否有订单在运行
        Order one = this.getOne(new LambdaQueryWrapper<Order>()
                .eq(Order::getCustomerId, loginId)
                .in(Order::getStatus,Constants.orderStatus.getRunOrderStatus()));
        if(one!=null){
            return JSONResult.error("你已有订单在运行");
        }
        //生成订单号
        String no = CodeGenerateUtils.generateOrderSn(loginId);
        //保存订单信息
        Order order = saveOrder(orderDto, loginId, no);
        //保存账单信息
        initeOrderBill(no);
        //在redis中查找范围内的司机
        List<DriverGeoDto> driverGeoDtos = searchDriver(orderDto);
        //根据司机的配置再次筛选匹配的司机
        List<DriverGeoDto> drivers = searchDriverBySetting(driverGeoDtos, orderDto);
        //推送订单给司机:MQ
        pushOrderToDriver(order,drivers);
        //  返回订单号给前端
        return JSONResult.success(no);
    }


    /**
     * 保存订单信息
     * */
    public Order saveOrder(OrderDto orderDto,Long loginId,String no){

        //将orderDto中的值赋给order
        Order order = orderDto.orderDtoToOrder(orderDto);
        //设置订单序列号
        order.setOrderNo(no);
        order.setCustomerId(loginId);
        order.setCreateTime(new Date());
        order.setEndPlaceLatiude(orderDto.getEndPlaceLatiude());
        //设置接单状态
        order.setStatus(RConst.Num.INT_0);
        //当前取出来的是json格式的对象
        Object extra = StpUtil.getExtra(Constants.CURRENT_LOGIN_KEY);
        Login login = JSONObject.parseObject(extra.toString(), Login.class);
        order.setCustomerName(login.getName());
        order.setCustomerPhone(login.getPhone());
        order.setCustomerPhoto(login.getAvatar());
        //设置顾客的好处费
        order.setFavourAmount(new BigDecimal(RConst.Num.INT_0));
        //设置初始化以及订单价格
        //获取预计里程
        String expectsMileage = orderDto.getExpectsMileage().toString();
        //获取预计价格
        String valuation = valuationOpenFeign.getValuation(expectsMileage).getData().toString();
        order.setExpectsOrderAmount(new BigDecimal(valuation));
        super.save(order);
        return order;
    }

    /**
     * 初始化账单
     * */
    private void initeOrderBill(String no) {
        JSONResult billDto = valuationOpenFeign.getBillDto(LocalDateTime.now().getHour());
        BillDto billDto1 = JSONObject.parseObject(JSONObject.toJSONString(billDto.getData()), BillDto.class);
        OrderBill orderBill = new OrderBill();
        BeanUtils.copyProperties(billDto1,orderBill);
        orderBill.setOrderId(IdUtil.getSnowFlackId());
        orderBill.setOrderNo(no);
        orderBillMapper.insert(orderBill);
    }

    /**
     * 在redis中查找范围内的司机
     */
    private List<DriverGeoDto> searchDriver(OrderDto orderDto) {
        //根据乘客开始位置的经纬度确定搜索范围
        Point point = new Point(Double.valueOf(orderDto.getStartPlaceLongitude()),
                Double.valueOf(orderDto.getStartPlaceLatitude()));
        //Distance(半径，单位)
        Circle circle = new Circle(point,new Distance(RConst.Num.INT_2, Metrics.KILOMETERS));
        //构建查询条件
        RedisGeoCommands.GeoRadiusCommandArgs args = 
                RedisGeoCommands.GeoRadiusCommandArgs.newGeoRadiusArgs();
        args.includeDistance() //包含距离
                .includeCoordinates() //包含坐标
                .sortAscending() //由近到远
                .limit(RConst.Num.INT_5); //选几个
        //从redis中取出符合范围的司机
        GeoResults<RedisGeoCommands.GeoLocation<Object>> radius =
                redisTemplate.opsForGeo().radius(CacheConstants.DRIVER_POINT_SETTING, circle, args);
        List<GeoResult<RedisGeoCommands.GeoLocation<Object>>> content = radius.getContent();
        //将获取到的司机封装成一个对象集合
        return content.stream().map(item-> new DriverGeoDto(Long.valueOf(item.getContent().getName().toString()),
                    item.getDistance().getValue(),
                    item.getDistance().getUnit()))
                    .collect(Collectors.toList());
    }

    /**
     * 根据司机id查找司机的配置再次筛选匹配的司机
     */
    private List<DriverGeoDto> searchDriverBySetting(List<DriverGeoDto> driverGeoDtos,OrderDto orderDto) {
        List<DriverGeoDto> drivers = new ArrayList<>();
        //循环司机集合
        for (DriverGeoDto driverGeoDto : driverGeoDtos) {
            //判断司机是否还在线
            Boolean isOnline = redisTemplate.hasKey(CacheConstants.DRIVER_POINT_SETTING + driverGeoDto.getDriverId());
            if(!isOnline){
                continue;
            }
            DriverSettingRedisDto driverSetting =
                    (DriverSettingRedisDto) redisTemplate.opsForValue()
                            .get(CacheConstants.DRIVER_POINT_SETTING + driverGeoDto.getDriverId());
            //判断乘客起始位置与司机设置的接受距离
            if (driverGeoDto.getValue()>driverSetting.getRangeDistance()){
                continue;
            }
            //判断司机最大的接受里程
            if(orderDto.getExpectsMileage().intValue()>driverSetting.getOrderDistance()){
                continue;
            }
            //判断司机是否自动听单
            if (!driverSetting.getListenService()){
                continue;
            }
            drivers.add(driverGeoDto);
        }
        return drivers;
    }

    /**
     * 将消息推送给司机
     * */
    private void pushOrderToDriver(Order order,List<DriverGeoDto> drivers) {
        //发送订单信息给那些司机
        for (DriverGeoDto driver : drivers) {
            PushOrderToDriver pushOrderToDriver = new PushOrderToDriver();
            //将订单中的信息赋给推送信息的对象
            BeanUtils.copyProperties(order,pushOrderToDriver);
            //距离司机的距离
            pushOrderToDriver.setToDriverMileage(driver.getValue());
            //构建推送订单信息到MQ
            Message<PushOrderToDriver> message = MessageBuilder.withPayload(pushOrderToDriver).build();
            rocketMQTemplate.syncSend(CacheConstants.PUSH_ORDER_TO_DRIVER_TOPIC+":"+
                                String.format(CacheConstants.PUSH_ORDER_TO_DRIVER_TAG,driver.getDriverId()),
                    message);

        }
    }

    /**
     * 司机pullMQ消息
     * */
    @Override
    public JSONResult getMQMessage() {
        //获取当前登录的司机id
        long driverId = StpUtil.getLoginIdAsLong();
        List<PushOrderToDriver> list = new ArrayList<>();
        try {
            //拉取消息队列，指定topic
            Set<MessageQueue> messageQueues =
                    pullConsumer.fetchSubscribeMessageQueues(CacheConstants.PUSH_ORDER_TO_DRIVER_TOPIC);
            //遍历当前队列
            for (MessageQueue messageQueue : messageQueues) {
                //通过偏移量(Offset)来获取消息 ：当前队列的消费位置
                long offset = pullConsumer.fetchConsumeOffset(messageQueue, true);
                //拉取消息，需要指定tags拼接司机ID， 来区分司机
                String tag=String.format(CacheConstants.PUSH_ORDER_TO_DRIVER_TAG,driverId);
                //获取 那个Queue里面的那个tag的那个offset的值
                PullResult pullResult = pullConsumer.pull(messageQueue, tag, offset, 32);
                //判断拉取结果是否有数据
                if(pullResult != null || pullResult.getPullStatus().equals(PullStatus.FOUND)){
                    //获取消息列表
                    List<MessageExt> msgFoundList = pullResult.getMsgFoundList();
                    if(msgFoundList == null || msgFoundList.size() == RConst.Num.INT_0)continue;
                    for (MessageExt messageExt : msgFoundList) {
                        //messageExt为byte数据类型，将messageExt转换为String类型
                        String message =new String(messageExt.getBody(), StandardCharsets.UTF_8);
                        //将messageExt转化为对象
                        PushOrderToDriver pushOrderToDriver = JSONObject.parseObject(message, PushOrderToDriver.class);
                        list.add(pushOrderToDriver);
                    }
                }
                //保证消息只消费一次
                if(pullResult != null){
                    //重要：修改消息的消费位置，如果位置不后移，消息会一直被消费
                    pullConsumer.updateConsumeOffset(messageQueue,pullResult.getNextBeginOffset());
                }
            }
            return JSONResult.success(list);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 顾客取消订单
     * */
    @Override
    public JSONResult cancelOrder(String orderId) {
        Order one = super.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNo, orderId));
        if (one==null){
            return JSONResult.success("您还未下单");
        }
        //判断订单是否被接单：0为未结单
        if(one.getStatus().equals(RConst.Num.INT_0)){
            one.setStatus(Constants.orderStatus.ORDER_STATUS_CUSTOMER_CANCEL_ORDER);
            one.setUpdateTime(new Date());
            super.updateById(one);
        }else {
            //其他情况下撤销订单也要修改订单状态
            //收取手续费、扣信用值等操作
            one.setStatus(Constants.orderStatus.ORDER_STATUS_CUSTOMER_CANCEL_ORDER);
            one.setUpdateTime(new Date());
            super.updateById(one);
        }
        return JSONResult.success();
    }

    /**
     * 司机抢单：1.查询订单状态是否为0(未被接单状态)
     * 2.判断司机状态是否是可以抢单的(前端已解决)
     * 3.修改订单状态为 1(已接单状态),添加司机信息
     * 4.集成redisson上锁
     * 5.封装对象给前端展示
     * */
    @Override
    public JSONResult killOrderHandle(String orderId) {
        Order one = this.getOne(new LambdaQueryWrapper<Order>()
                .eq(Order::getOrderNo, orderId)
                .eq(Order::getStatus, RConst.Num.INT_0));
        //获取锁
        RLock lockStock = redissonClient.getLock(Constants.DRIVER_GRAB_ORDER_LOCK);
        //上锁
        lockStock.lock();
        try {
            if(one!=null){
                //修改订单信息
                updateOrder(one);
                KillOrderVo killOrderVo = new KillOrderVo();
                BeanUtils.copyProperties(one,killOrderVo);
                return JSONResult.success(killOrderVo);
            }
        } finally {
            //释放锁
            lockStock.unlock();
        }
        return JSONResult.error(ErrorCode.FAILED_TO_GRAB_ORDER);
    }

    /**
     * 司机取消订单：1.修改订单状态
     * 2.记录司机的summery
     * */
    @Override
    public JSONResult driverCancelOrder(String orderId) {
        //修改订单的状态
        Order one = this.getOne(new LambdaQueryWrapper<Order>()
                .eq(Order::getOrderNo, orderId)
                .eq(Order::getStatus, RConst.Num.INT_1));
        if (one!=null){
            one.setStatus(RConst.Num.INT_10);
            one.setUpdateTime(new Date());
            Long id = StpUtil.getLoginIdAsLong();
            super.updateById(one);
            driverSummaryOpenFeign.updateDriverSummery(id);
            return JSONResult.success("订单取消成功");
        }
        return JSONResult.error("订单取消失败");
    }

    /**
     * 判断是否有订单在运行
     * */
    @Override
    public JSONResult checkRunningOrder(Integer userType) {
        //查询人为乘客
        if (userType==1){
            Order one = super.getOne(new LambdaQueryWrapper<Order>()
                    .eq(Order::getCustomerId,StpUtil.getLoginIdAsLong())
                    .in(Order::getStatus,Constants.orderStatus.checkRunningOrderStatus()));
            FromLocation fromLocation = new FromLocation();
            fromLocation.setStartPlace(one.getStartPlace());
            fromLocation.setStartLatitude(one.getStartPlaceLatitude());
            fromLocation.setStartLongitude(one.getStartPlaceLongitude());
            ToLocation toLocation = new ToLocation();
            toLocation.setEndPlace(one.getEndPlace());
            toLocation.setEndLatitude(one.getEndPlaceLatiude());
            toLocation.setEndLongitude(one.getEndPlaceLongitude());
            return JSONResult.success(new CheckRunningOrderVo(one.getStatus(),one.getOrderNo(),fromLocation,toLocation));
        }else {
            //查询人为司机
            Order order = super.getOne(new LambdaQueryWrapper<Order>()
                    .eq(Order::getDriverId,StpUtil.getLoginIdAsLong())
                    .in(Order::getStatus,Constants.orderStatus.checkRunningOrderStatus()));
            KillOrderVo killOrderVo = new KillOrderVo();
            BeanUtils.copyProperties(order,killOrderVo);
            return JSONResult.success(killOrderVo);
        }

    }

    /**
     * 司机到达接客地点
     * */
    @Override
    public JSONResult arriveStartPlace(String orderNO) {
        Date date = new Date();
        Order one = super.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNo, orderNO));
        one.setArriveTime(date);
        one.setUpdateTime(date);
        one.setStatus(RConst.Num.INT_2);
        super.updateById(one);
        return JSONResult.success();
    }

    /**
     * 开始代驾
     * */
    @Override
    public JSONResult startDrivingHandle(String orderNO) {
        Date date = new Date();
        Order one = super.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNo, orderNO));
        one.setStatus(RConst.Num.INT_3);
        one.setStartTime(date);
        one.setUpdateTime(date);
        super.updateById(one);
        return JSONResult.success();
    }

    /**
     * 结束代驾
     * */
    @Override
    public JSONResult endDrivingHandle(String orderNO) {
        Date date = new Date();
        Order one = super.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNo, orderNO));
        one.setStatus(RConst.Num.INT_4);
        one.setEndTime(date);
        one.setUpdateTime(date);
        super.updateById(one);
        return JSONResult.success();
    }

    /**
     * 保存司机的实时定位-用于司乘同显
     * */
    @Override
    public JSONResult saveDriverLocation(DriverEverytimeLocation driverEverytimeLocation) {
        /*GeoOperations<String, Object> geo = redisTemplate.opsForGeo();
        Point point = new Point(driverEverytimeLocation.getLongitude(), driverEverytimeLocation.getLatitude());
        Long add = geo.add(CacheConstants.DRIVER_POINT_LOCATION,
                           point, driverEverytimeLocation.getOrderNo());*/
        //设置过期时间
        /*redisTemplate.expire(CacheConstants.DRIVER_POINT_LOCATION+driverEverytimeLocation.getOrderNo()
                ,RConst.Num.INT_12, TimeUnit.SECONDS);*/
        redisTemplate.opsForValue()
                .set(CacheConstants.DRIVER_POINT_LOCATION+driverEverytimeLocation.getOrderNo(),driverEverytimeLocation);
        System.out.println(CacheConstants.DRIVER_POINT_LOCATION+driverEverytimeLocation.getOrderNo());
        return JSONResult.success();
    }

    /**
     * 定时拉取司机的当前位置
     * */
    @Override
    public JSONResult pullDriverLocation(String orderNO) {
        //Point集合
        /*List<Point> position = redisTemplate.opsForGeo()
                .position(CacheConstants.DRIVER_POINT_LOCATION, orderNO);
                return JSONResult.success(position[0]);
                */
        Object o = redisTemplate.opsForValue()
                .get(CacheConstants.DRIVER_POINT_LOCATION+orderNO);
        /*DriverEverytimeLocation driverEverytimeLocation =
                    JSONObject.parseObject(o.toString(), DriverEverytimeLocation.class);*/
        return JSONResult.success(o);
    }


    /**
     * 结算订单
     * */
    @Override
    public JSONResult confirmOrder(ConfirmOrderDto confirmOrderDto) {
        //修改订单
        Order one = super.getOne(new LambdaQueryWrapper<Order>()
                .eq(Order::getOrderNo, confirmOrderDto.getOrderNo())
                .eq(Order::getStatus, RConst.Num.INT_4));
        updateOrderConfirm(one);
        //修改账单
        OrderBill orderBill = updateOrderBill(confirmOrderDto, one);
        return JSONResult.success(orderBill);
    }

    /**
     * 结算订单：修改账单的方法
     * */
    private OrderBill updateOrderBill(ConfirmOrderDto confirmOrderDto, Order one) {
        OrderBill orderBill = orderBillMapper.selectOne(new LambdaQueryWrapper<OrderBill>()
                .eq(OrderBill::getOrderNo, confirmOrderDto.getOrderNo()));
        //订单总金额 real_order_amount
        orderBill.setRealOrderAmount(one.getRealOrderAmount());
        //实付款金额 real_pay_amount
        double other = confirmOrderDto.getTollFee() + confirmOrderDto.getOtherFree() + confirmOrderDto.getParkingFee();
        orderBill.setRealPayAmount(one.getRealOrderAmount().add(new BigDecimal(other)));
        //路桥费 toll_amount
        orderBill.setTollAmount(new BigDecimal(confirmOrderDto.getTollFee()));
        //超出基础里程多少公里 exceed_base_mileage
        //超出的里程
        BigDecimal overMileage = one.getRealMileage().subtract(orderBill.getBaseMileage());
        //计算超出的钱
        BigDecimal overMoney = overMileage.multiply(orderBill.getExceedBaseMileageEveryKmAmount());
        //判断是否超出里程
        if(one.getRealMileage().compareTo(orderBill.getBaseMileage())>RConst.Num.INT_0){
            //超出基础里程多少公里 exceed_base_mileage
            orderBill.setExceedBaseMileage(overMileage);
            //超出基础里程的价格 exceed_base_mileage_amount
            orderBill.setExceedBaseMileageAmount(overMoney);
        } else{
            //没超出则为0
            orderBill.setExceedBaseMileage(new BigDecimal(RConst.Num.INT_0));
            orderBill.setExceedBaseMileage(new BigDecimal(RConst.Num.INT_0));
        }
        //里程费(基础+超出) mileage_amount
        orderBill.setMileageAmount(orderBill.getBaseMileageAmount().add(overMoney));
        //等时时长 waiting_minute
        Long waitTime = (one.getStartTime().getTime() - one.getEndTime().getTime()) /
                (RConst.Num.INT_1000 * RConst.Num.LONG_60);
        orderBill.setWaitingMinute(waitTime.intValue());//单位分钟
        //超出免费等时的分钟数 execeed_base_waiting_minute
        if(orderBill.getFreeBaseWaitingMinute() < waitTime){
            //计算超出分钟数
            int overWaitTime = waitTime.intValue()-orderBill.getFreeBaseWaitingMinute();
            orderBill.setExeceedBaseWaitingMinute(
                    new BigDecimal(overWaitTime));
            //计算超出分钟数价格
            BigDecimal multiply = orderBill.getExeceedBaseWaitingEveryKmAmount().multiply(new BigDecimal(overWaitTime));
            //等时费用(超出分钟*每分钟价格) waiting_amount
            orderBill.setWaitingAmount(multiply);
        }
        //返程里程(等于订单里程) return_mileage
        orderBill.setReturnMileage(one.getRealMileage());
        //超出免费返程部分的里程 exceed_free_base_return_mileage
        BigDecimal overFreeMileage = one.getRealMileage().subtract(orderBill.getFreeBaseReturnMileage());
        if(one.getRealMileage().compareTo(orderBill.getFreeBaseReturnMileage())>RConst.Num.INT_0){
            orderBill.setExceedFreeBaseReturnMileage(overFreeMileage);
            //返程费(超出公里*每公里价格) return_amont
            orderBill.setReturnAmont(overFreeMileage.multiply(orderBill.getExceedBaseReturnEveryKmAmount()));
        }else {
            orderBill.setExceedFreeBaseReturnMileage(new BigDecimal(RConst.Num.INT_0));
            orderBill.setReturnAmont(new BigDecimal(RConst.Num.INT_0));
        }
        //其他费用 other_amount
        orderBill.setOtherAmount(new BigDecimal(confirmOrderDto.getOtherFree()));
        //停车费 parking_amount
        orderBill.setParkingAmount(new BigDecimal(confirmOrderDto.getParkingFee()));
        //修改时间 update_time
        orderBill.setUpdateTime(new Date());
        orderBillMapper.updateById(orderBill);
        return orderBill;
    }

    /**
     * 结算订单：修改订单的方法
     * */
    private void updateOrderConfirm(Order one) {
        //实际里程
        one.setRealMileage(one.getExpectsMileage());
        //返程：即实际里程
        one.setReturnMileage(one.getExpectsMileage());
        //实际订单价格
        String realValuation = valuationOpenFeign.getValuation(one.getRealMileage().toString()).getData().toString();
        one.setRealOrderAmount(new BigDecimal(realValuation));
        one.setUpdateTime(new Date());
        super.updateById(one);
    }


    /**
     * 司机抢单后修改订单信息的方法
     * */
    private void updateOrder(Order one) {
        Date date = new Date();
        //修改订单状态
        one.setStatus(RConst.Num.INT_1);
        //添加司机信息
        Object extra = StpUtil.getExtra(Constants.CURRENT_LOGIN_KEY);
        Login login = JSONObject.parseObject(extra.toString(), Login.class);
        one.setDriverId(login.getId());
        one.setDriverName(login.getName());
        one.setDriverPhone(login.getPhone());
        one.setDriverPhoto(login.getAvatar());
        //修改司机接单时间
        one.setAcceptTime(date);
        //修改订单修改时间
        one.setUpdateTime(date);
        super.updateById(one);
    }
}

